<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>

<body>
    <div class="app">
        <div>
            <span>用户名:</span>
            <span>
                <input type="text" v-model.lazy="username">
            </span>
            <span>{{pmt}}</span>
        </div>
    </div>
    <script src="./js/vue.js"></script>
    <script>
        var xm = new Vue({
            el: '.app',
            data: {
                username: '',
                pmt: ''
            },
            methods: {
                checkname(val) {
                    setTimeout(() => {
                        if (val === 'azhe123') {
                            this.pmt = '用户名已使用，请重新输入'
                        } else {
                            this.pmt = '输入成功'
                        }
                    },1000)
                }
            },
            watch: {
                username: function (val) {
                    this.checkname(val)
                    this.pmt = '验证中......'
                }

            }

        })

    </script>
</body>

</html>